package com.vehicle.common.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

/**
 * Created by yantingbin on 2017/7/3.
 */
public class RedisProperties {
    @Value("${spring.redis.password:#{null}}")
    private String password;

    @Autowired
    private Pool pool;

    @Autowired
    private Cluster cluster;

    public Pool getPool() {
        return pool;
    }

    public void setPool(Pool pool) {
        this.pool = pool;
    }

    public Cluster getCluster() {
        return cluster;
    }

    public void setCluster(Cluster cluster) {
        this.cluster = cluster;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * Pool properties
     */
    public static class Pool{
        /**
         * Max number of "idle" connections in the pool.Use a negative value to indicate
         * an unlimited number of idle connections
         */
        @Value("${spring.redis.pool.max-idle:8}")
        private int maxIdle;

        /**
         * Target for the minimum number of idle connections to maintain in the pool.This
         * setting only has an effect if it is positive.
         */
        @Value("${spring.redis.pool.min-idle:0}")
        private int minIdle;

        /**
         * Max number of connections that can be allocated by the pool at a given time.
         * Use a negative value for no limit.
         */
        @Value("${spring.redis.pool.max-active:8}")
        private int maxActive;

        /**
         * Maximum amount of time(in milliseconds) a connection allocation
         * should block before throwing an exception when the pool is
         * exhauseted.Use a negative value to block indefinitely.
         */
        @Value("${spring.redis.pool.max-wait:-1}")
        private int maxWait;

        public int getMaxIdle() {
            return maxIdle;
        }

        public void setMaxIdle(int maxIdle) {
            this.maxIdle = maxIdle;
        }

        public int getMinIdle() {
            return minIdle;
        }

        public void setMinIdle(int minIdle) {
            this.minIdle = minIdle;
        }

        public int getMaxActive() {
            return maxActive;
        }

        public void setMaxActive(int maxActive) {
            this.maxActive = maxActive;
        }

        public int getMaxWait() {
            return maxWait;
        }

        public void setMaxWait(int maxWait) {
            this.maxWait = maxWait;
        }
    }
    public static class Cluster{
        /**
         * Cluster model single or cluster
         */
        @Value("${spring.redis.cluster-model:single}")
        private String clusterModel;
        /**
         * Comma-separated list of host:port pairs.
         */
        @Value("${spring.redis.nodes:#{null}}")
        private String nodes;

        public String getClusterModel() {
            return clusterModel;
        }

        public void setClusterModel(String clusterModel) {
            this.clusterModel = clusterModel;
        }

        public String getNodes() {
            return nodes;
        }

        public void setNodes(String nodes) {
            this.nodes = nodes;
        }
    }
}
